package com.wgworkshop.pems.controller;

import com.wgworkshop.pems.common.CommonUtils;
import com.wgworkshop.pems.common.ResponseData;
import com.wgworkshop.pems.model.AttendanceCountByClassView;
import com.wgworkshop.pems.model.AttendanceDetailByClassView;
import com.wgworkshop.pems.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统计信息控制器。
 * Created by wlc on 2017/12/26.
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    private final StatisticsService statisticsService;

    @Autowired
    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    @GetMapping("/attendance-count")
    ResponseData<List<AttendanceCountByClassView>> getAttendanceCount(@RequestParam String start, @RequestParam String end) {
        List<AttendanceCountByClassView> result = statisticsService.getAttendanceCount(CommonUtils.toDate(start), CommonUtils.toDate(end));
        return new ResponseData<List<AttendanceCountByClassView>>().success(result);
    }

    @GetMapping("/attendance-detail")
    ResponseData<List<AttendanceDetailByClassView>> getAttendanceDetail(String start, String end, Integer week, Integer num) {
        List<AttendanceDetailByClassView> result = statisticsService.getAttendanceDetail(CommonUtils.toDate(start), CommonUtils.toDate(end), week, num);
        return new ResponseData<List<AttendanceDetailByClassView>>().success(result);
    }
}
